package com.heima.feigns.fallback;

import com.heima.feigns.WmFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmUser;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class WmFeignFallback implements FallbackFactory<WmFeign> {
    @Override
    public WmFeign create(Throwable throwable) {
        // 远程调用时产生的异常
        throwable.printStackTrace();
        return new WmFeign() {
            @Override
            public ResponseResult<WmUser> findByName(String name) {
                log.error("参数:{}",name);
                log.error("自媒体 findByName 远程调用出错了!! {}",throwable.getMessage());

                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR,"远程调用失败");
            }

            @Override
            public ResponseResult<WmUser> save(WmUser wmUser) {
                log.error("参数:{}",wmUser);
                log.error("自媒体 save 远程调用出错了!! {}",throwable.getMessage());

                return ResponseResult.errorResult(AppHttpCodeEnum.REMOTE_SERVER_ERROR,"远程调用失败");
            }
        };
    }
}
